'''
Created on Aug 25, 2011

@author: david
'''

from pspy.gae.actiondomain import PspyAction

class Create(PspyAction):
    """
    Default Action 
    spawns index.gen
    """
    def execute(self): 
        from app.Ranger.agents import AccessAgent
        from pspy import Notification
    
        req = self.request
        pwd = req.getParameter("pwd","none")
        
        # set up
        rslts = "200::Ok"
        nxtPage = "/Ranger/Index.gen"
        try:
            # check for form output v. processing
            if pwd == 'none':
                # send out form
                nxtPage = '/Ranger/acct/Create.gen' 
            else:
                # gather remaining params
                uid = req.getParameter("email")
                name = req.getParameter("name")
                
                # create account
                AccessAgent().create(uid,pwd,name)
                
                req.setAttribute("msg","Thank you for joining Payment Ranger. Check you email for account activation message.")
                
        except Exception as ex:
            Notification("Acct Create Error").setException(ex)
            rslts = "500::%s" % str(ex)
            
        # all done, return to client
        req.setAttribute("results",rslts)
        req.setResponsePage(nxtPage)    
        
        return req.getResponse()
    
    def sess_check(self):
        return True